﻿using System;
using System.Collections;
using FX.CC.Andon.Entity.BasicDataManage;
using FX.CC.Andon.Service.BasicDataManage;
using FX.CC.Andon.Utility.Json;

namespace FX.CC.Andon.Business.BasicDataManage
{
    /// <summary>
    /// 异常明细类别业务层
    /// </summary>
    public class ETypeCategoryBusiness
    {
        private readonly ETypeCategoryService _dal = new ETypeCategoryService();

        /// <summary>
        /// 添加异常明细类别
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        public bool AddETypeCategory(string data)
        {
            var model = new ETypeCategoryEntity();
            var rows = (ArrayList)JsonHelper.Decode(data);
            foreach (Hashtable row in rows)
            {
                model.CatID = Guid.NewGuid();
                model.ETypeCode = row["ETypeCode"].ToString();
                model.CatName = row["CatName"].ToString();
                model.CatDesc = row["CatDesc"] != null ? row["CatDesc"].ToString() : "";
            }
            return _dal.AddETypeCategory(model);
        }

        /// <summary>
        /// 修改异常明细类别
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        public bool ModifyETypeCategory(string data)
        {
            var model = new ETypeCategoryEntity();
            var rows = (ArrayList)JsonHelper.Decode(data);
            foreach (Hashtable row in rows)
            {
                model.CatID = new Guid(row["CatID"].ToString());
                model.CatName = row["CatName"].ToString();
                model.CatDesc = row["CatDesc"] != null ? row["CatDesc"].ToString() : "";
            }
            return _dal.ModifyETypeCategory(model);
        }

        /// <summary>
        /// 获取异常明细类别单条信息
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public string GetETypeCategoryInfo(string id)
        {
            return JsonHelper.Encode(_dal.GetETypeCategoryInfo(id));
        }

        /// <summary>
        /// 获取异常明细类别分页
        /// </summary>
        /// <returns></returns>
        public string GetETypeCategoryList(ETypeCategoryQcEntity qcmodel)
        {
            var total = _dal.GetETypeCategoryCount(qcmodel);
            var list = _dal.GetETypeCategoryList(qcmodel);
            return JsonHelper.Encode(total, list);
        }
    }
}
